﻿using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ExtendedDataTableLibrary;

public partial class _Default : System.Web.UI.Page 
{
    ExtendedDataTable extendedDt = new ExtendedDataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        ds.ReadXml(Server.MapPath("SampleData.xml"));
        DataTable dt = ds.Tables[0];

        extendedDt.ImportDataTable(dt);

        extendedDt.FormatProperties.ColumnNames["FriendId"] = "Id";
        extendedDt.FormatProperties.ColumnNames["FriendName"] = "Name";
        extendedDt.FormatProperties.ColumnNames["FriendSurname"] = "Surname";
        extendedDt.FormatProperties.ColumnNames["Gender"] = "Gender";
        extendedDt.FormatProperties.ColumnNames["PlayedBy"] = "Played By";

    }
    protected void btnToWord_Click(object sender, EventArgs e)
    {
        extendedDt.ToWord(@"C:\Friends.docx");
    }
    protected void btnToExcel_Click(object sender, EventArgs e)
    {
        extendedDt.ToExcel(@"C:\Friends.xlsx");
    }
    protected void btnToHtml_Click(object sender, EventArgs e)
    {
        lblPreview.Text=extendedDt.ToHTML();
    }
    protected void btnSendMail_Click(object sender, EventArgs e)
    {
        extendedDt.MailProperties.SmtpClient.Host = "localhost";
        extendedDt.SendMail("oztamer@hotmail.com", "oztamer@hotmail.com", "Friends");
    }
    protected void btnPrint_Click(object sender, EventArgs e)
    {
        Context.Items.Add("Table", extendedDt);
        Server.Transfer("Print.aspx");
    }
    protected void btnFill_Click(object sender, EventArgs e)
    {
        extendedDt.DataProperties.Connection.ConnectionString = "data source=.;initial catalog=dummy;integrated security=SSPI";
        extendedDt.DataProperties.Command.CommandText = "SELECT * FROM Dummy";
        extendedDt.Fill();
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        extendedDt.Update();
    }
}
